<?php
$db = $GLOBALS[RC]->getDb();
$sql = "
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `cms_category`;
CREATE TABLE `cms_category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `cms_category_version`;
CREATE TABLE `cms_category_version` (
  `version_id` int(11) NOT NULL,
  `main_id` int(11) NOT NULL,
  PRIMARY KEY (`version_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `cms_content`;
CREATE TABLE `cms_content` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `cms_content_version`;
CREATE TABLE `cms_content_version` (
  `version_id` int(11) NOT NULL,
  `main_id` int(11) NOT NULL,
  PRIMARY KEY (`version_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$db->executeBatch($sql);

$com = App::getModel('system/component')
        ->setCode('Cms')
        ->setName('cms.component_name')
        ->setAuthor('Coder Soul Studio')
        ->setWebsite('www.codersoul.com')
        ->setEmail('codersoulstudio@gmail.com')
        ->setVersion('0.1')
        ->save();
$menu = App::getModel('system/menu')
        ->setName('cms.cms_manage')
        ->setUrl('')
        ->setComponentId($com->getId())
        ->save();
App::getModel('system/menu')
        ->setName('cms.category_index')
        ->setUrl('/cms/category/index')
        ->setComponentId($com->getId())
        ->setParentId($menu->getId())
        ->save();
App::getModel('system/menu')
        ->setName('cms.content_index')
        ->setUrl('/cms/content/index')
        ->setComponentId($com->getId())
        ->setParentId($menu->getId())
        ->save();

$entity = App::getModel('system/dms_entity')
            ->setComponentId($com->getId())
            ->setClassName('Component_Cms_Model_Category')
            ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('id')
        ->setPropertyType('integer')
        ->setFieldType('int')
        ->setIsPrimary(TRUE)
        ->setIsIncrement(TRUE)
        ->setInputType(NULL)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('parent_id')
        ->setPropertyType('integer')
        ->setFieldType('int')
        ->setRequired(FALSE)
        ->setDefaultValue(0)
        ->setInputType('select')
        ->setLabel('cms.parent_category')
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('name')
        ->setPropertyType('string')
        ->setFieldType('varchar')
        ->setLength(50)
        ->setInputType('textbox')
        ->setLabel('system.label.name')
        ->setVersionable(TRUE)
        ->setRequired(TRUE)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('description')
        ->setPropertyType('string')
        ->setFieldType('varchar')
        ->setLength(100)
        ->setInputType('textbox')
        ->setLabel('system.label.description')
        ->setVersionable(TRUE)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('status')
        ->setPropertyType('string')
        ->setFieldType('varchar')
        ->setLength(50)
        ->setInputType(NULL)
        ->setRequired(TRUE)
        ->setLabel('system.label.status')
        ->setVersionable(TRUE)
        ->setDefaultValue(CONSTANT_STATUS_PUBLISHED)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('id_path')
        ->setPropertyType('string')
        ->setFieldType('varchar')
        ->setLength(200)
        ->setRequired(TRUE)
        ->setInputType(NULL)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('website_id')
        ->setPropertyType('integer')
        ->setFieldType('int')
        ->setRequired(TRUE)
        ->setInputType(NULL)
        ->setVersionable(TRUE)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('created_time')
        ->setPropertyType('timestamp')
        ->setFieldType('timestamp')
        ->setRequired(TRUE)
        ->setUpdateable(FALSE)
        ->setInputType(NULL)
        ->setVersionable(TRUE)
        ->setLabel('system.label.created_time')
        ->save();

$entity = App::getModel('system/dms_entity')
            ->setComponentId($com->getId())
            ->setClassName('Component_Cms_Model_Content')
            ->save();
App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('id')
        ->setPropertyType('integer')
        ->setFieldType('int')
        ->setIsPrimary(TRUE)
        ->setIsIncrement(TRUE)
        ->setInputType(NULL)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('category_id')
        ->setPropertyType('integer')
        ->setFieldType('int')
        ->setInputType('select')
        ->setLabel('cms.category_id')
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('title')
        ->setPropertyType('string')
        ->setFieldType('varchar')
        ->setRequired(TRUE)
        ->setLength(50)
        ->setVersionable(TRUE)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('author')
        ->setPropertyType('string')
        ->setFieldType('varchar')
        ->setLength(50)
        ->setVersionable(TRUE)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('start_time')
        ->setPropertyType('timestamp')
        ->setFieldType('timestamp')
        ->setInputType('datetime')
        ->setVersionable(TRUE)
        ->setLabel('system.label.start_time')
        ->setVersionable(TRUE)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('end_time')
        ->setPropertyType('timestamp')
        ->setFieldType('timestamp')
        ->setVersionable(TRUE)
        ->setInputType('datetime')
        ->setVersionable(TRUE)
        ->setLabel('system.label.end_time')
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('content')
        ->setPropertyType('string')
        ->setFieldType('text')
        ->setRequired(TRUE)
        ->setInputType('editor')
        ->setVersionable(TRUE)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('updator')
        ->setPropertyType('string')
        ->setFieldType('varchar')
        ->setRequired(TRUE)
        ->setInputType(NULL)
        ->setVersionable(TRUE)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('created_time')
        ->setPropertyType('timestamp')
        ->setFieldType('timestamp')
        ->setRequired(TRUE)
        ->setUpdateable(FALSE)
        ->setInputType(NULL)
        ->setVersionable(TRUE)
        ->setLabel('system.label.created_time')
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('modified_time')
        ->setPropertyType('timestamp')
        ->setFieldType('timestamp')
        ->setRequired(TRUE)
        ->setInsertable(FALSE)
        ->setUpdateable(FALSE)
        ->setTimestampAction('auto_update_time')
        ->setLabel('system.label.modified_time')
        ->setVersionable(TRUE)
        ->setInputType(NULL)
        ->save();

App::getModel('system/dms_property')
        ->setEntityId($entity->getId())
        ->setName('website_id')
        ->setPropertyType('integer')
        ->setFieldType('int')
        ->setRequired(TRUE)
        ->setInputType(NULL)
        ->setVersionable(TRUE)
        ->save();